package LeetCode.LC119;

import java.util.ArrayList;
import java.util.List;

/**
 * @author corn
 * @create 2020-11-10-22:21
 */
public class SolutionTest {
    public static void main(String[] args) {
        Solution solution = new Solution();
        List<Integer> row = solution.getRow(6);
        System.out.println(row.toString());
    }
}
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> list = new ArrayList<>();

        list.add(1);
        if(rowIndex == 0){
            return list;
        }
        list.add(1);
        if(rowIndex == 1){
            return list;
        }
        for(int i = 2; i <= rowIndex; i++){
            int size = i + 1;
            for(int j = size - 2; j > 0; j--){
                if(j == size - 2){
                    if(j == 1){
                        list.add(j, list.get(j - 1) + list.get(j) );
                    }else{
                        list.add(j, list.get(j - 1) + list.get(j) );
                    }
                }else if(j == 1){
                    list.set(j, list.get(j - 1)+list.get(j));
                }else{
                    list.set(j, list.get(j - 1) + list.get(j));
                }
            }
        }
        return list;
    }
}
